/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aal.business;

import com.aal.bean.WarehouseFacadeLocal;
import com.aal.entity.Warehouse;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author quy
 */
@Stateless
public class WarehouseManagement implements WarehouseManagementLocal {
    @EJB
    private WarehouseFacadeLocal warehouseFacade;
    
    @Override
    public boolean createWarehouse(String warehouseName, String warehouseLocation, String warehouseDescription) {
        try{
        Warehouse warehouse = new Warehouse();
        warehouse.setWarehouseID(Integer.MIN_VALUE);
        warehouse.setWarehouseName(warehouseName);
        warehouse.setWarehouseLocation(warehouseLocation);
        warehouse.setWarehouseDescription(warehouseDescription);
        warehouseFacade.create(warehouse);
        }catch(Exception ex){
            return false;
        }
        return true;
    }
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    @Override
    public boolean editWarehouse(String warehouseName, String warehouseLocation, String warehouseDescription) {
        try{
            Warehouse warehouse = warehouseFacade.findName(warehouseName);
            if(warehouseName != null){
                warehouse.setWarehouseName(warehouseName);
            }
            if(warehouseLocation != null){
                warehouse.setWarehouseLocation(warehouseLocation);
            }
            if(warehouseDescription != null){
                warehouse.setWarehouseDescription(warehouseDescription);
            }
            warehouseFacade.edit(warehouse);
        }catch(Exception ex){
            return false;
        }
        return true;
    }
    @Override
    public boolean deleteWarehouse(String warehouseName){
        try{
            Warehouse warehouse = warehouseFacade.findName(warehouseName);
            warehouseFacade.remove(warehouse);
        }catch(Exception ex){
            return false;
        }
        return true;
    }
    @Override
    public List<Warehouse> findWarehouse(String warehouseName) {
        return warehouseFacade.findWarehouse(warehouseName);
    }

    @Override
    public List<com.aal.entity.Warehouse> getAllWarehouses() {
        return warehouseFacade.findAll();
    }
    
    
}
